package com.system.web.spring;


import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

//import com.workflow.WorkFlowUtils;
import com.common.db.JsonVO;
import com.common.db.Pg;
import com.common.utils.BeanUtils;
import com.system.domain.T_pic;
import com.system.mapper.T_picMapper;
//import com.system.service.T_picMapperService;

//@Service
//@Transactional
@Controller
@RequestMapping("/t_pic")

public class T_picController
{
	private static Logger log = Logger.getLogger(T_picController.class.getName());

	//@Autowired
    //private T_picService service;

	//@Autowired
	//private WorkFlowUtils workFlowUtils;

	@Resource
	private T_picMapper mapper;
	//private int id;
	//private int[] ids;
	private Pg pg;

	/**
	 * 1、获取 T_pic信息列表，并且在列表页面展示
	 * @param request
	 * @return Pg，json格式
	 */
	@RequestMapping("/getAllT_pic")
	@ResponseBody
	public Pg getAllT_pic(HttpServletRequest request){
        int pageSize = 10;
        int startIndex = 0;
        T_pic t_pic = new T_pic();
        try{
	        if(request.getParameter("pageSize")!=null){
	        	pageSize = BeanUtils.stringToInt("pageSizeFlag", request.getParameter("pageSize"));
	        }
	        if(request.getParameter("startIndex")!=null){
	            startIndex = BeanUtils.stringToInt("startIndexFlag", request.getParameter("startIndex"));
	        }
	        if(request.getParameter("process_code")!=null){ //取得动作流 流程英文名称，后台查询数据关联使用
	        	t_pic.setProcess_code(request.getParameter("process_code"));
	        }
			if(request.getParameter("name")!=null&&!"".equals(request.getParameter("name"))){
	        	t_pic.setName(request.getParameter("name"));
	        }
			if(request.getParameter("memo")!=null&&!"".equals(request.getParameter("memo"))){
	        	t_pic.setMemo(request.getParameter("memo"));
	        }
			if(request.getParameter("ext1")!=null&&!"".equals(request.getParameter("ext1"))){
	        	t_pic.setExt1(request.getParameter("ext1"));
	        }
			if(request.getParameter("ext2")!=null&&!"".equals(request.getParameter("ext2"))){
	        	t_pic.setExt2(request.getParameter("ext2"));
	        }
			if(request.getParameter("ext3")!=null&&!"".equals(request.getParameter("ext3"))){
	        	t_pic.setExt3(request.getParameter("ext3"));
	        }
      	    if(request.getParameter("id")!=null&&!"".equals(request.getParameter("id"))){
	        	t_pic.setId(new Integer(request.getParameter("id")));
	        }

	        if(request.getParameter("startdate")!=null&&!"".equals(request.getParameter("startdate"))){
	        	t_pic.setStartdate(request.getParameter("startdate"));
	        }
	        if(request.getParameter("enddate")!=null&&!"".equals(request.getParameter("enddate"))){
	        	t_pic.setEnddate(request.getParameter("enddate"));
	        }
	        t_pic.setStartNo( startIndex );
	        t_pic.setEndNo( startIndex + pageSize );
	    	List<T_pic> findAll = mapper.findAll(t_pic);
	        int totalCount = mapper.findCountAll(t_pic);
	       	pg = new Pg(findAll, totalCount, pageSize, startIndex);
	       	request.setAttribute("t_picList", findAll);
		    request.setAttribute("pg", pg);
	    } catch (Exception e) {
			e.printStackTrace();
			log.error("------query t_picList error:"+e);
		}

		return pg;
	}

	/**
	 * 2、新增保存  T_pic信息并且返回成功或者失败信息json格式结果如：result:[success/error]
	 * @param user
	 * @param request
	 * @return
	 */
	@RequestMapping("/saveT_pic")
	@ResponseBody
	public JsonVO saveT_pic(T_pic t_pic, HttpServletRequest request,HttpServletResponse response){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);
		//如果有特殊需求，需要将json对象值转成java实体对象属性值
		if(mapper.save(t_pic)>0){
	        vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 3、修改T_pic信息并且返回成功或者失败信息json格式结果如：result:[success/error]
	 * @param t_pic
	 * @param request
	 * @return JsonVO
	 */
	@RequestMapping("/updateT_pic")
	@ResponseBody
	public JsonVO updateT_pic(T_pic t_pic, HttpServletRequest request){
		JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);
		//如果有特殊值需要处理，在此处手工转换
		//T_pic t_picTemp = mapper.findById(t_pic);
		//t_picTemp.setXXX(t_pic.getXXX());
		//if(mapper.update(t_picTemp)){

		if(mapper.update(t_pic)>0){
	        vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 4、根据id查询T_pic单个信息并显示在修改页面
	 * @param id
	 * @param request
	 * @return T_pic json格式字符串
	 */
	@RequestMapping("/getT_pic")
	@ResponseBody
	public T_pic getT_pic(Integer id,HttpServletRequest request){
		T_pic t_pic = new T_pic();
		t_pic.setId(id);
		return mapper.findById(t_pic);
	}

	/**
	 * 5、删除T_pic根据id
	 * @param id
	 * @param request
	 * @param response
	 * return JsonVO ：json格式字符串
	 */
	@RequestMapping("/delT_pic")
	@ResponseBody
	public JsonVO delT_pic(Integer id,HttpServletRequest request,HttpServletResponse response){
        JsonVO vo = new JsonVO();
		vo.setResult("error");
		vo.setJieguo(false);

		T_pic t_pic = new T_pic();
		t_pic.setId(id);

		if(mapper.delete(t_pic)>0){
			vo.setResult("success");
	        vo.setJieguo(true);
		}
		return vo;
	}

	/**
	 * 6、跳转到t_pic/toT_picList查询所有数据页面
	 *  return /WEB-INF/views/system/t_pic/t_picList.jsp
	 */
    @RequestMapping(value = "/toT_picList")
    public String toT_picList() {
    	log.debug("------跳转到/WEB-INF/views/system/t_pic/t_picList.jsp------");
        return "system/t_pic/t_picList";
    }

	/**
	 * 7、新增、修改、详情页面t_pic/toT_picCurd跳转
     * system/t_pic/T_picCurd.jsp
	 */
    @RequestMapping(value = "/toT_picCurd")
    public String toT_picCurd() {
    	log.debug("------跳转到/WEB-INF/views/system/t_pic/t_picCurd.jsp------");
        return "system/t_pic/t_picCurd";
    }

    /**
	 * 8、批量删除T_pic根据主键id
	 * 是否要实现批量删除，待考虑，基本上用途不大
	 * @param id
	 * @param request
	 * @param response
	@RequestMapping("/delT_picBatch")
	public String delT_picBatch(HttpServletRequest request,HttpServletResponse response){
		String[] ids = request.getParameterValues("ids");
		System.out.println("------ids="+ids);
		T_pic t_pic = new T_pic();
		int j=0;
		for(int i =0;i< ids.length;i++){
			j++;
			log.error("------ids[i]="+ids[i]);
			t_pic.setId(new Integer(ids[i]).intValue());
			mapper.delete(t_pic);
		}
		if(j==ids.length){
			log.debug("------t_pic批量删除成功！------");
		}else{
			log.error("------t_pic批量删除部分成功！部分失败！------");
		}

		return "redirect:/t_pic/getAllT_pic";
	}
*/



}









